<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/resources/css/admin/main.css"/>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/resources/css/validate/main.css"/>
<script type="text/javascript" src="<%=request.getContextPath() %>/resources/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/resources/js/core/jquery.cms.core.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/resources/js/admin/main.js"></script>
<script type="text/javascript" charset="utf-8" src="<%=request.getContextPath() %>/resources/js/kindeditor/kindeditor.js"></script>										
<script type="text/javascript" src="<%=request.getContextPath() %>/resources/js/kindeditor/kindeditor-all.js"></script>
<script charset="utf-8" src="<%=request.getContextPath() %>/resources/js/kindeditor/editor/lang/zh_CN.js"></script>									
      
</head>
<body>
<div id="content">
	<h3 class="admin_link_bar">
		<jsp:include page="incdetails.jsp"></jsp:include>
	</h3>
	<form method="post" action="<%=request.getContextPath() %>/admin/channeldetails_manage/update" id="myform" name="myform">
	<table width="800" cellspacing="0" cellPadding="0">
		<thead><tr><td colspan="2">添加明细</td></tr></thead>
		<tr>
			<td class="rightTd" width="200px">标题:</td>
			<td class="leftTd"><input type="text" name="channelDetailsTitle" value="${cd.channelDetailsTitle}" id="channelDetailsTitle" size="30" onblur="checkName(this);"/></td>
		</tr>
		<tr>
			<td class="rightTd">服务类型:</td>
			<td class="leftTd">
				<select name="channel.parent.id" id="channel" onchange="setSub(this);">
					
					<c:forEach var="c" items="${channel}"> 
						<option value="${c.id}"  ${cd.channel.parent.id eq c.id?"selected":""}>${c.name}</option>
					</c:forEach>
				</select>
				&nbsp;	&nbsp;子服务类型
				<select name="channel.id" id="channelsub">
					<c:forEach var="c" items="${channelchild}">
						<option value="${c.id}" ${cd.channel.id eq c.id}>${c.name}</option>
					</c:forEach>
				</select>
			</td>
		</tr>
		<tr>
			<td class="rightTd">信息来源:</td>
			<td class="leftTd">
		<input id="channelDetailsFrom" type="text" value="${cd.channelDetailsFrom}" name="channelDetailsFrom" size="30" />
		
		</tr>
		<tr>
			<td class="rightTd">搜索关键字:</td>
			<td class="leftTd"><input type="text" name="channelDetailsIndex" value="${cd.channelDetailsIndex}" size="30"/></td>
		</tr>
		<tr>
			<td class="rightTd">标题图片:</td>
			<td class="leftTd">
			
			<c:choose>
				<c:when test="${cd.channelDetailsPic==''}">
					<input id="ss" type="file" name="pic" size="30" onchange="javascript:document.getElementById('cs').value=this.value;"/>
				</c:when>
				<c:otherwise>
				<span id="imgspan"><img height="50px" width="100" src="<%=request.getContextPath() %>/resources/fileupload/${cd.channelDetailsPic}"><a href="javascript:return(0);" onclick="hidImg();">删除</a></span>
			
				</c:otherwise>
			</c:choose>
		<input type="hidden" id="cs" name="channelDetailsPic" id="imgfileName" value="${cd.channelDetailsPic}"/>
			</td>
		</tr>
		<tr>
			<td class="rightTd">是否首页显示:</td>
			<td class="leftTd">
				<input type="radio" name="channelDetailsIshome"  ${cd.channelDetailsIshome eq 0?"checked='checked' ":"" }   value="0"/>否
				<input type="radio" name="channelDetailsIshome" ${cd.channelDetailsIshome eq 1?"checked='checked' ":"" } value="1"/>是
			</td>
		</tr>
		<tr>
			<td class="rightTd">内容:</td>
			<td class="leftTd">
				
				<textarea rows="4" cols="60" id="channelDetailsContent" name="channelDetailsContent" style="width:1000px;height:300px;visibility:hidden;">${cd.channelDetailsContent }</textarea>
			</td>
		</tr>
		<tr>
		<input  id="channelDetailsId" type="hidden" value="${cd.channelDetailsId}" name="channelDetailsId" size="30" />
		<input id="channelDetailsCreateName" type="hidden" value="${cd.channelDetailsCreateName}" name="channelDetailsCreateName" size="30" />
		<input id="channelDetailsCreateDate2" type="hidden" value="${cd.channelDetailsCreateDate}" name="channelDetailsCreateDate2" size="30" />
			<td colspan="2" class="centerTd"><input type="button" onclick="validate();" value="添加目录明细"/><input type="reset"/></td>
		</tr>
	</table>
	</form>
</div>
<script type="text/javascript">
KindEditor.ready(function(K) {
	var editor1 = K.create('textarea[name="channelDetailsContent"]', {
		cssPath : '<%=request.getContextPath() %>/resources/js/kindeditor/plugins/code/prettify.css',
		uploadJson : '<%=request.getContextPath() %>/resources/js/kindeditor/jsp/upload_json.jsp',
		fileManagerJson : '<%=request.getContextPath() %>/resources/js/kindeditor/jsp/file_manager_json.jsp',
		allowFileManager : true,
		afterBlur : function() {
			this.sync();
			K.ctrl(document, 13, function() {
			K('form[name=myform]')[0].submit();
			});
			K.ctrl(this.edit.doc, 13, function() {
			K('form[name=myform]')[0].submit();
			});
			}
	});
	prettyPrint();
});
	function hidImg(){
		$("#imgspan").html("<input id='ss' type='file' name='pic'  onchange='javascript:document.getElementById('cs').value=this.value;'/>");
	}
	function setSub(obj){
		
		var sub=document.getElementById("channelsub");
		sub.options.length=0;
		var cid=$("#channel").val();
		 $.ajax({
	     		type:"post",
	            url:"<%=request.getContextPath() %>/admin/channeldetails_manage/getChannelSub/"+cid,
	            dataType:"text",
	          
	    
		     success: function(msg){ 
		    	// $("#channelsub").options.length=0; 
		    	if(msg.length<=0){
		    		$("#channelsub").append("<option value='-1'>没有二级目录</option>");
		    	}else{ 
		    		$("#channelsub").append(msg);
		      	}
		    	
		       }   
			});  	
	}

	function validate(){
		
		//$("#cs").val()=$("#ss").val();
		document.getElementById("cs").value=$("#ss").val();
		
		if($("#channelDetailsTitle").val().length<=0){
			
			alert("名称必须填");
		}if($("#channel").val()==-1){
			alert("请选择一级目录");
		}
		else{
			
			$("#myform").submit();
		}
		
	}
	function checkName(obj){
		if(obj.value().length<=0){
			
			alert("目录名称必须填");
		}
		
	}
</script>
</body>
</html>